package com.mybatis.common;

/**
 * @author liuxiaoding
 * 插入排序
 * @Date 2021/8/9
 **/
public class InsertSort {
    public static void main(String[] args) {
        int [] a = {1,6,8,7,3,5,16,4,8,36,13,44};
        sort(a);
        System.out.println("");
        for (int i:a) {

            System.out.print(i + " ");
        }
    }

    public static void sort(int [] arr){
        for(int i=1;i<arr.length;i++){
            int temp=arr[i];
            int j;
            for(j=i-1;j>0;j--){
                if(arr[j]>temp){
                    arr[j+1]=arr[j];
                }else{
                    break;
                }
            }
            arr[j+1]=temp;
        }
    }


}
